#include <sys/types.h>          /* See NOTES */
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>

#define BACKLOG 5


int main(int argc, char *argv[]){
	
	int sockfd;
	int add;
	struct sockaddr_in addr;
	char buf[BUFSIZ] = {};

	if(argc < 3){
		fprintf(stderr, "%s<addr><port>\n", argv[0]);
		return 0;
	}

	if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
		perror("socket");
		return 0;
	}
	addr.sin_family = AF_INET;
	addr.sin_port = htons(atoi( argv[2]) );

	if(inet_aton(argv[1], &addr.sin_addr) == 0){
		fprintf(stderr, "Invalid address\n");
		return 0;
	}
	add = connect(sockfd, (struct sockaddr *)&addr, sizeof(addr));
	if(add == -1){
		perror("connect");
		return 0;
	}
	while(1){

		printf("INput->");
		fgets(buf, BUFSIZ, stdin);
		write(sockfd, buf, strlen(buf));
		
	}
	close(sockfd);

	return 0;
}
